<template>
  <div class="page goods-spread">
    <div class="scroll-view">
      <customHeader middleTitle="推广" rightTitle="保存" @rightCallBack="saveImg" />
      <div class="page-body">
        <img class="post-img" :src="imageUrl" v-if="imageUrl" alt />
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue';
import customHeader from '../../components/header/header';
import { Toast } from 'mint-ui';
import jsBridge from "../../tools/jsBridge";
export default {
  name: 'spread',
  data() {
    return {
      imageUrl: ""
    };
  },
  methods: {
    //保存图片
    saveImg() {
      try {
        jsBridge.savePicture({ url: this.imageUrl }, function (response) {
          if (response && (response.success === true || response.success === 'true')) {
            Toast("保存成功");
          } else {
            Toast("保存失败,请检查是否开启照片写入权限");
          }
        });
      } catch (e) {
        Toast("保存异常");
      }
    },
    getData() {
      const url = "/newapp/goods/service/queryMiniPoster.do";
      const goodsId = this.$route.query['id'];
      if (!goodsId) {
        Toast("未获取到商品id");
        return;
      }
      this.ajax({
        url: url,
        type: "post",
        data: { goodsId: goodsId },
        controlLoading: true
      })
        .then(res => {
          if (res.success) {
            const data = res.resultObject;
            if (data && data["imageUrl"]) {
              this.imageUrl = data.imageUrl;
            }
          } else {
            Toast(res.msg);
          }
        })
        .catch((err) => {

        });
    },
  },
  components: {
    customHeader,
  },
  created() {
    this.getData();
  },
};
</script>
<style lang='scss' scoped>
@import "goodsManage";
</style>
